package com.salary.controller;
import com.salary.entity.view.ChartModel;
import com.salary.service.IEmployeesService;
import com.salary.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页统计
 */
@Controller
@RequestMapping("/api/main")
public class MainController {

    @Autowired
    private IEmployeesService iEmployeesService;


    /**
     * 进入列表页面
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return "/admin/sjtj/index";
    }


    /**
     * 统计员工
     * @return
     */
    @RequestMapping("/getCountAll")
    @ResponseBody
    public Result getCountAll() {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("userCount",this.iEmployeesService.list().size());
        return Result.reOk("查询成功",map);
    }


    /**
     * 统计echart
     * @return
     */
    @RequestMapping("/getChartCountAll")
    @ResponseBody
    public Result getChartCountAll() {
        Map<String,Object> map=new HashMap<String,Object>();
        List<String> day=new ArrayList<>();
        List<BigDecimal> count=new ArrayList<>();
        List<ChartModel> chartModelList=iEmployeesService.getChart();
        for (ChartModel chartModel : chartModelList) {
            day.add(chartModel.getName());
            count.add(chartModel.getSfhj());
        }
        map.put("day",day);
        map.put("count",count);
        return Result.reOk("查询成功",map);
    }


}
